<?php

declare(strict_types=1);

namespace App\CustHub\Model;

use Mine\MineModel;

/**
 * @property int $id 
 * @property int $uid 
 * @property int $main_uid 
 * @property string $name 名称
 * @property string $avatar 头像
 * @property int $type 类型：0=客户群 1=webhook
 * @property int $wechat_type 微信类型：0=个微 1=企微
 * @property int $room_id 群ID
 * @property int $listen_robot_id 监听微号ID
 * @property array $speaker_ids 主讲人ID
 * @property array $business_info 业务信息
 * @property int $is_plat 是否官方：0=否 1=是
 * @property string $webhook_url 
 * @property \Carbon\Carbon $created_at 
 * @property \Carbon\Carbon $updated_at 
 * @property-read null|ChRobot $robot 
 * @property-read null|ChRoom $room 
 * @property-read null|\Hyperf\Database\Model\Collection|ChUser[] $shareAccount 
 */
class ChRoomBroadcastSource extends MineModel
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'ch_room_broadcast_source';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'uid', 'main_uid', 'name', 'avatar', 'type', 'wechat_type', 'room_id', 'listen_robot_id', 'speaker_ids', 'business_info', 'is_plat', 'webhook_url', 'created_at', 'updated_at'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'uid' => 'integer', 'main_uid' => 'integer', 'type' => 'integer', 'wechat_type' => 'integer', 'room_id' => 'integer', 'listen_robot_id' => 'integer', 'speaker_ids' => 'array', 'business_info' => 'array', 'is_plat' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];


    /**
     * 群
     * @return \Hyperf\Database\Model\Relations\HasOne
     */
    public function room(): \Hyperf\Database\Model\Relations\HasOne
    {
        return $this->hasOne(ChRoom::class, 'id', 'room_id');
    }

    public function robot(): \Hyperf\Database\Model\Relations\HasOne
    {
        return $this->hasOne(ChRobot::class, 'id', 'listen_robot_id');
    }

    /**
     * 共享账号
     * @return \Hyperf\Database\Model\Relations\BelongsToMany
     */
    public function shareAccount(): \Hyperf\Database\Model\Relations\BelongsToMany
    {
        return $this->belongsToMany(ChUser::class,'ch_room_broadcast_source_share_account','source_id','uid');
    }
}
